<template>
  <!-- 添加在轮播图区块下方 -->
  <div class="counselor-marquee">
    <h2 class="section-title">专业心理咨询师团队</h2>
    <Vue3Marquee :duration="30" pause-on-hover v-if="counselorList.length>0">
      <div
          v-for="(counselor, index) in counselorList"
          :key="counselor.counselorId"
          class="counselor-card"
          @click="goCounselorDetail(counselor.counselorId)"
      >
        <div class="avatar-wrapper">
          <img
              :src="counselor.avatar"
              alt="咨询师头像"
              class="avatar"
          >
        </div>
        <div class="info">
          <h3 class="name">姓名：{{ counselor.username }}</h3>
          <h3 class="name">昵称：{{ counselor.nickname }}</h3>
          <p class="title">职位：{{ counselorTitlesMapper(counselor.title) }}</p>
          <p class="expertise">擅长领域：{{ counselor.expertise }}</p>
        </div>
      </div>
    </Vue3Marquee>
    <el-empty v-else description="暂无咨询师数据"/>
  </div>
</template>

<script setup>
// 在现有script setup部分添加以下内容
import {getCurrentInstance, onMounted, ref} from 'vue';
import {listCounselorList} from "@/api/counselor/counselor.js";

const {proxy} = getCurrentInstance();
const {counselor_titles} = proxy.useDict('counselor_titles');

//  咨询师职位字典映射
function counselorTitlesMapper(value) {
  for (let i = 0; i < counselor_titles.value.length; i++) {
    if (counselor_titles.value[i].value === value) {
      return counselor_titles.value[i].label;
    }
  }
}

// 咨询师列表数据
const counselorList = ref([]);

// 获取咨询师列表
const getCounselors = async () => {
  try {
    const res = await listCounselorList();
    if (res.data) {
      counselorList.value = res.data;
    }
  } catch (error) {
    console.error('获取咨询师列表失败:', error);
  }
};

// 跳转咨询师详情页
const goCounselorDetail = (id) => {
  console.log('跳转详情页', id)
  proxy.$router.push({
    path: '/counselorDetails',
    query: {  // 使用 query 传参
      counselorId: id,
    }
  })
};

onMounted(() => {
  getCounselors();
});
</script>

<style scoped>
/* 添加以下样式 */
.counselor-marquee {
  max-width: 1200px;
  margin: 40px auto;
  padding: 0 20px;
}

.section-title {
  color: #333;
  font-size: 24px;
  margin-bottom: 20px;
  padding-left: 10px;
}

.counselor-card {
  width: 280px;
  height: 500px;
  margin: 0 15px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  transition: transform 0.3s;
  overflow: hidden;
}

.counselor-card:hover {
  transform: translateY(-5px);
}

.avatar-wrapper {
  height: 250px;
  overflow: hidden;
}

.avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.info {
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.name {
  color: #333;
  font-size: 18px;
  margin-bottom: 8px;
}

.title {
  color: #666;
  font-size: 14px;
  margin-bottom: 10px;
}

.el-tag {
  margin-right: 8px;
  margin-bottom: 8px;
}

.expertise {
  color: #888;
  font-size: 13px;
  line-height: 1.4;
  margin-top: 10px;
}
</style>
